<?php 
	session_start(); 
	include_once("../phpServices/Entities.php");
	include_once("../phpServices/Enum.php");
	include_once("../phpServices/Services.php");
	include_once("../phpServices/GlobalFunction.php");
	
	if(isset($_POST["submit"]))
	{
		$UserCode = GetCurrentUserCode();
		$CourseCheckInDTO = new CourseCheckInDTO();
		$CourseCheckInDTO->StudentCode = $UserCode;
		$CourseCheckInDTO->CourseID = $_POST["HiddenCourseID"];
		$CourseCheckInDTO->CourseScheduleID = $_POST["HiddenCourseScheduleID"];
		$image = $_POST["HiddenImgPath"];
		$CourseCheckInDTO->CheckInImage = base64_decode(str_replace("data:image/webp;base64,","",$image));
		 // echo "<img style='width:100px;height:100px;border:1px solid black' src='$image' />";
		 // echo "<img style='width:100px;height:100px;border:1px solid black' src='data:image/webp;base64," . base64_encode($CourseCheckInDTO->CheckInImage) . "' />";
		 // echo $image;
		// echo '<br/><br/><br/><br/>'. $CourseCheckInDTO->CheckInImage;
		// echo '<br/><br/><br/><br/>' . file_get_contents("C:\wamp\www\check-in-system\Resources\Images\person-clip-art.png");		
		$CourseCheckInService = new CourseCheckInService();
		if($CourseCheckInService->CheckDataExists($CourseCheckInDTO))
		{
			$CourseCheckInService->UpdateCourseCheckIn($CourseCheckInDTO);
		}else{
			$CourseCheckInService->InsertCourseCheckIn($CourseCheckInDTO);
		}
		Header("Location:index.php");
	}
?>